#!/usr/bin/env python

# encoding: utf-8

'''
 * Create File __init__.py
 * Created by leixu on 2017/9/18
 * IDE PyCharm
'''
from selenium import webdriver
import os, platform


class SessionHolder(object):
    def __init__(self):
        self.driver = None

    def _driver_selector(self, driver_type="chrome", config={}):
        """

        :param driver_type: 这个主要是选择webdriver的类型，默认chrome
        :param config: 传入的配置
        :return:
        """
        s = os.path.abspath(os.path.join(os.path.realpath(__file__), "../../drivers"))
        if driver_type is "chrome":
            if platform.system() == "Windows":
                self.driver = webdriver.Chrome(os.path.join(s, "chromedriver.exe"), **config)
            elif platform.system() == "Linux":
                self.driver = webdriver.Chrome(os.path.join(s, "chromedriver"), **config)

    def chose_driver_type(self, type="chrome", config={}):
        self._driver_selector(type, config)

    def close_driver(self):
        self.driver.quit()
